//
//  DownLoadDataHelper.m
//  OurMenu
//
//  Created by 尹坤 on 15/10/9.
//  Copyright © 2015年 尹坤. All rights reserved.
//

#import "DownLoadDataHelper.h"
#import "Reachability.h"
@implementation DownLoadDataHelper
- (void)downLoadDataWithUrlString:(NSString *)string
{
    
   
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:string]];
    [request setHTTPMethod:@"GET"];
    //request.HTTPMethod = @"post";
    if ([DownLoadDataHelper AbnormalNetworkConnection]) {
    NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *  data, NSURLResponse *  response, NSError *  error) {
       dispatch_async(dispatch_get_main_queue(), ^{
//           if ([DownLoadDataHelper AbnormalNetworkConnection]) {
//               
               [self.sendDataDelegete sendDataBack:data isRequest:YES];
           //}else{
               //[self.sendDataDelegete sendDataBack:data isRequest:NO];
           //}
          
       });
        
    }];
        
    
    [task resume];
    }else{
         [self.sendDataDelegete sendDataBack:nil isRequest:NO];
    }
}
+ (BOOL)AbnormalNetworkConnection{
    Reachability *reach = [Reachability reachabilityWithHostName:@"www.baidu.com"];
    if ([reach currentReachabilityStatus] != ReachableViaWiFi && [reach currentReachabilityStatus] != ReachableViaWWAN) {
        return NO;
    }else{
        return YES;
    }
}

@end
